home *** CD-ROM | disk | FTP | other *** search
Wrap
#pragma once // The CSpinner class lets you spin the mouse cursor using a VBL task. It compiles for 68K and PowerPC, yet it uses no dirty tricks. // Author: François Pottier (pottier@clipper.ens.fr) // Release: November 2, 1995 // This code may be used freely. Please drop me a note in email if you find bugs, possible enhancements, or just to say you like it. // View this file as Geneva 9pt on a 17" monitor for best appearance. // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // The code was written for CW7. It uses PowerPlant's macros for exception handling, but is otherwise independent from PowerPlant. // Here is how this class is typically used: // // void MyLengthyTask (void) // { // CSpinner theSpinner(myAcurID); // Create a stack-based object // theSpinner.Spin(); // Start the VBL task // // // ... execute your gnarly lengthy task, which is allowed to raise exceptions ... // // theSpinner.Stop(); // Stop the VBL task // } // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Layout of the 'acur' resource. #pragma options align=mac68k struct SAcurRec { short itsFrameCount; short itsCurrentFrame; CursHandle itsFrame[1]; // This array is in fact variable-sized }; #pragma options align=reset typedef SAcurRec* SAcurPtr; typedef SAcurPtr* SAcurHandle; // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // The VBL task has different calling conventions on the PowerPC and on 68K. Happily, it is possible to keep things relatively simple thanks to the compiler's register directive. #ifdef __powerc #define VBLTASKPROTOTYPE static void MyTask (VBLTaskPtr inTaskPtr) #else #define VBLTASKPROTOTYPE static pascal void MyTask (register VBLTaskPtr inTaskPtr : __A0) #endif // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // If you want to add virtual members to this class, BEWARE: the address of mTask should be the address of the whole object. The VBL task relies on this trick. class CSpinner { private: VBLTask mTask; // IMPORTANT: this must be the first member SAcurHandle mAcurHandle; // Handle to the cursor array short mTickInterval; // Time interval between two frames Boolean mTaskInstalled; // Allows additional sanity checks friend VBLTASKPROTOTYPE; // The VBL task itself has access to the object's private members public: CSpinner (short inAcurID); // Constructor reads in 'acur' and 'CURS' resources ~CSpinner (); // Destructor calls Stop if necessary void Spin (void); // Calls to these two methods should be balanced. void Stop (void); };